Sets every cell of target to value. A grid is always full, so there is nothing to grow: the grid keeps its width and height and every cell becomes value. It works on a grid handed to a script too.
grid_fill(target, value)| Name | Type |
|---|---|
target | grid |
value | element |
Nothing.
Sets every cell of target, a grid, to value. A grid is always full, so there is nothing to grow: the grid keeps its width and its height, and every cell becomes value. Whatever was in the cells before is gone.
grid_fill(board, 0); // every cell is now 0To fill only some of the cells, use grid_fill_region.
list_fill makes a list longer, up to its capacity. A grid cannot grow, so grid_fill never changes how many cells there are. It only changes what they hold. That is why it is named the same, but it is a different kind of job.
A script that takes a grid as a parameter works on the caller's own grid, so grid_fill inside a script fills the caller's grid, whatever size that is. Unlike grid_fill_region, it does not need the grid's width, because it goes through the cells one after another and does not care how they are laid out in rows. So it is the one grid function that works on a script's grid parameter.
| You do this | What happens |
|---|---|
give a value of the wrong kind, like grid_fill(board, "x") for a grid of numbers | the project is refused when it is checked, and the message says what kind the grid holds |
| give it a list or an array | refused when checked. Use list_fill for a list. An array has no fill function |
| give it the wrong number of arguments | refused when checked |
use it where a value is needed, like var x = grid_fill(board, 0); | refused when checked. grid_fill does a job and gives nothing back |
value is worked out once and copied before any cell changes, so grid_fill(board, board[# 2, 3]) fills every cell with whatever cell 2, 3 held a moment ago.
It visits every cell once, so the time grows with the size of the grid. Filling a small board when a level starts is nothing. Filling a big grid in every frame is a real part of the frame.
var board = grid_create(8, 6, 0);
grid_fill(board, -1); // every cell is -1
board[# 2, 3] = 5; // one cell changed, the other 47 are still -1A loop over every cell of the grid's vector, assigning one copy of value to each - O(W*H). value is worked out once and copied before the first cell changes, so grid_fill(board, board[# 2, 3]) fills with what that cell held a moment ago. It needs no width or height (it walks the cells, not the rows), so unlike the region functions it also works inside a script, on the CALLER's grid, whatever size that is: the grid parameter is a reference to the capacity-free vector base, which knows its own length. It never changes how many cells there are.